<template>
	<view class="">
		<view class="margin-bottom30">
			<u-tabs :list="list1" @click="handleTabs"></u-tabs>
		</view>
		<view class="padding-30">
			<view class="padding-30 bg-fff border-radius20 flex-between margin-bottom30" v-for="(item,index) in list" :key="index"
			@click="$tools.navigateTo('/pages/index/science-Information-info?id='+item.id)">
				<view class="margin-right20">
					<view class="fontSize-16 color-000 fontWeight-bold text-ellipsis margin-bottom20">
						{{item.title}}
					</view>
					<view class="fontSize-15 color-999">
						发布时间：{{item.createtime}}
					</view>
				</view>
				<image class="img-160 border-radius10" :src="item.image" mode=""></image>
			</view>
		</view>
		<u-empty v-if="list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"
			width="150px" height="150px" text="列表为空" textSize="18">
		</u-empty>
		<view style="padding-bottom: 100rpx;">
			<u-loadmore v-if="loading" status="loading" />
			<u-loadmore v-if="isLastPage" status="nomore" />
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				list1:[
					{name:'健康科普',type:1},
					{name:'高血压科普',type:2}
				],
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
				type:1
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.articleList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.articleList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.articleList();
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			// 选择tabs切换
			handleTabs(e){
				this.type = e.type
				this.page = 1
				this.limit = 10
				this.list = []
				this.articleList()
			},
			// 获取文章列表、
			async articleList() {
				let res = await this.$http.post(this.$api.article_list, {
					page: this.page,
					limit: this.limit,
					type:this.type
				}, {
					token: true
				})
				this.list = [...this.list, ...res.data]
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>